Learning Flex Basics (Part 2): Creating a Simple Calculator with Macromedia Flex
Table of Contents
- Introduction
- Building the Calculator
- Create the Application Object
- Add a Panel for the Calculator
- Add the Calculator Display
- Add a Grid to Lay Out the Buttons
- Add the Calculator Buttons
- Create the CalculatorController Class
- Add Properties to the Controller Class
- Add Controller Methods
- Instantiate the CalculatorController Class
- Complete Code Listing for calculator.mxml
- Complete Code Listing for CalculatorController.as
- Where to Go From Here
Building the Calculator
The calculator will have two parts: a view built in MXML; and a controller built as an ActionScript class. The view will contain all the visual elements of the calculator such as the display and buttons. The controller contains data that holds variables you need in order to keep track of the user's actions; it also contains methods that you will use to handle events, such as the user clicking a button.
Figure 1. The calculator you will build in this tutorial.
In building the calculator you will learn to use:
- The Application class
- The Panel container
- The Label element
- The Grid container
- The Button element
- An ActionScript class that includes:
- A class definition
- Properties
- Methods
- The if-else and switch-case control structures